package kr.hkit.barontest;

import java.util.ArrayList;

import com.example.androidtest.R;

import android.animation.ArgbEvaluator;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class Hero extends Activity {

	ArrayList<MyItem> arItem;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hero_list);

		arItem = new ArrayList<MyItem>();
		MyItem mi;
		mi = new MyItem(R.drawable.garen, "가렌");
		arItem.add(mi);
		mi = new MyItem(R.drawable.galio, "갈리오");
		arItem.add(mi);
		mi = new MyItem(R.drawable.gangplank, "갱플랭크");
		arItem.add(mi);
		mi = new MyItem(R.drawable.gragas, "그라가스");
		arItem.add(mi);
		mi = new MyItem(R.drawable.graves, "그레이브즈");
		arItem.add(mi);
		mi = new MyItem(R.drawable.nami, "나미");
		arItem.add(mi);
		mi = new MyItem(R.drawable.nasus, "나서스");
		arItem.add(mi);
		mi = new MyItem(R.drawable.nautilus, "노틸러스");
		arItem.add(mi);
		mi = new MyItem(R.drawable.nocturne, "녹턴");
		arItem.add(mi);
		mi = new MyItem(R.drawable.nunu, "누누");
		arItem.add(mi);
		mi = new MyItem(R.drawable.nidalee, "리달리");
		arItem.add(mi);
		mi = new MyItem(R.drawable.darius, "다리우스");
		arItem.add(mi);
		mi = new MyItem(R.drawable.diana, "다이에나");
		arItem.add(mi);
		mi = new MyItem(R.drawable.draven, "드레이븐");
		arItem.add(mi);
		mi = new MyItem(R.drawable.ryze, "라이즈");
		arItem.add(mi);
		mi = new MyItem(R.drawable.rammus, "람머스");
		arItem.add(mi);
		mi = new MyItem(R.drawable.lux, "럭스");
		arItem.add(mi);
		mi = new MyItem(R.drawable.rumble, "럼블");
		arItem.add(mi);
		mi = new MyItem(R.drawable.renekton, "레렉톤");
		arItem.add(mi);
		mi = new MyItem(R.drawable.leona, "레오나");
		arItem.add(mi);

		MyListAdapter MyAdapter = new MyListAdapter(this, R.layout.icontext,
				arItem);

		ListView MyList;
		MyList = (ListView) findViewById(R.id.hero_list);
		MyList.setAdapter(MyAdapter);

		MyList.setOnItemClickListener(mItemClickListener);

	}

	AdapterView.OnItemClickListener mItemClickListener = new AdapterView.OnItemClickListener() {
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			Intent intent = null;
			switch (position) {
			case 0:
				intent = new Intent(Hero.this, HeroText.class);
				startActivity(intent);
				break;
			}
		}
	};
}

// 리스트 뷰에 출력할 항목
class MyItem {
	MyItem(int aIcon, String aName) {
		Icon = aIcon;
		Name = aName;
	}

	int Icon;
	String Name;
}

// 어댑터 클래스
class MyListAdapter extends BaseAdapter {
	Context maincon;
	LayoutInflater Inflater;
	ArrayList<MyItem> arSrc;
	int layout;

	public MyListAdapter(Context context, int alayout, ArrayList<MyItem> aarSrc) {
		maincon = context;
		Inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		arSrc = aarSrc;
		layout = alayout;
	}

	public int getCount() {
		return arSrc.size();
	}

	public String getItem(int position) {
		return arSrc.get(position).Name;
	}

	public long getItemId(int position) {
		return position;
	}

	// 각 항목의 뷰 생성
	public View getView(final int position, View convertView, ViewGroup parent) {
		final int pos = position;
		if (convertView == null) {
			convertView = Inflater.inflate(layout, parent, false);
		}
		ImageView img = (ImageView) convertView.findViewById(R.id.img);
		img.setImageResource(arSrc.get(position).Icon);

		TextView txt = (TextView) convertView.findViewById(R.id.text);
		txt.setText(arSrc.get(position).Name);

		txt.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = null;

				String str = arSrc.get(pos).Name + "페이지를 불러옵니다.";
				Toast.makeText(maincon, str, Toast.LENGTH_SHORT).show();

			}
		});

		return convertView;
	}
}
